package com.android.duininsuoai.adapt;

import android.widget.ImageView;
import android.widget.TextView;

import com.android.duininsuoai.R;
import com.android.duininsuoai.model.auction.AuctionOrderListData;
import com.android.duininsuoai.model.auction.UpdateAuctionBean;
import com.android.duininsuoai.utils.MyLog;
import com.android.duininsuoai.utils.ObjectUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2016/8/10.
 */
public class listMineOrderAdapt extends BaseQuickAdapter<AuctionOrderListData.DataBean.ListBean, MyOrderUserViewHolder> {
    private String id;
    private HashMap<String,UpdateAuctionBean> updateBean = new HashMap<>();
    private HashMap<String,MyOrderUserViewHolder> myViewHolderList = new HashMap<>();
    private String Mid = "";

    public listMineOrderAdapt(int layoutResId, List<AuctionOrderListData.DataBean.ListBean> data) {
        super(layoutResId, data);
    }


    public HashMap<String, UpdateAuctionBean> getUpdateBean() {
        return updateBean;
    }

    public void setUpdateBean(HashMap<String, UpdateAuctionBean> updateBean) {
        this.updateBean = updateBean;
    }
    public void setCurrentId(String currentid)
    {
        this.id = currentid;
    }

    public void setMid(String Mid) {
        this.Mid = Mid;
    }

    //更新当前出价竞拍人和消除过期商品
    public void notifyUsernameDataAndRemove() {

        if (myViewHolderList.containsKey(id)) {
            if(updateBean.get(id).getPrice()>0) {
                myViewHolderList.get(id).getBid_people().setText(updateBean.get(id).getUsername());
                myViewHolderList.get(id).getAuctioning_price().setText("当前价: ￥" + updateBean.get(id).getPrice());
            }
        }
    }

    @Override
    protected void convert( MyOrderUserViewHolder holder,AuctionOrderListData.DataBean.ListBean mineChoujiangdata) {

        if(mineChoujiangdata.getAuctioning_itemType()==AuctionOrderListData.DataBean.ListBean.THREE)
        {

            if(!(myViewHolderList.containsKey(mineChoujiangdata.getId()))) {
                myViewHolderList.put(mineChoujiangdata.getId(), holder);
            }
            ObjectUtils.photo2(mContext,mineChoujiangdata.getAuctioning_thumb(),(ImageView)holder.getView(R.id.item_list_mine_dingdang_img));
            holder.setTime_position(holder.getLayoutPosition());
            holder.setVisible(R.id.auctioning_ll, true);
            holder.setVisible(R.id.auction_ll, false);
            holder.setVisible(R.id.promised_ll,false);
            holder.setText(R.id.marking_price,mineChoujiangdata.getMarket_price());
            holder.setText(R.id.auctioning_price, mineChoujiangdata.getAuctioning_price());
            holder.setText(R.id.bid_people, mineChoujiangdata.getAuctioning_username());
        }
        else {
            MyLog.e("getOrder_code()",mineChoujiangdata.getOrder_code()+"");
            switch (mineChoujiangdata.getOrder_code()) {
                case 1:
                    //待领奖
                    holder.setVisible(R.id.auctioning_ll, false);
                    holder.setVisible(R.id.promised_ll,false);
                    holder.setVisible(R.id.auction_ll, true);
                    ImageView v = (ImageView) holder.getView(R.id.item_list_mine_dingdang_img2);
                    ObjectUtils.photo2(mContext, mineChoujiangdata.getThumb(), v);
                    int c_time = Integer.parseInt(mineChoujiangdata.getC_time());
                    long msl = (long) c_time * 1000;
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String text = format.format(msl);
                    ((TextView) holder.getView(R.id.turnover_time)).setText(text);
                    ((TextView) holder.getView(R.id.marking_price2)).setText(mineChoujiangdata.getMarket_price());
                    ((TextView) holder.getView(R.id.turnover_price)).setText(mineChoujiangdata.getPrice());
                    ((TextView) holder.getView(R.id.bid_number2)).setText(mineChoujiangdata.getMid_count());
                    ((TextView) holder.getView(R.id.turnover_people)).setText(mineChoujiangdata.getUsername());
                    float percent = (Float.parseFloat(mineChoujiangdata.getPrice()) / Float.parseFloat(mineChoujiangdata.getMarket_price()))*100;
                    float savepercent = 100 - percent;
                    DecimalFormat df = new DecimalFormat(".00");
                    String aishang_savepercent =df.format(savepercent);
                    holder.setText(R.id.save_percent, aishang_savepercent+"%");
                    holder.setVisible(R.id.waiting_topay_tv, true);
                    holder.setText(R.id.waiting_topay_tv, "去领取");
                    break;
                case 2:
                    //待支付
                    holder.setVisible(R.id.auctioning_ll, false);
                    holder.setVisible(R.id.promised_ll,false);
                    holder.setVisible(R.id.auction_ll, true);
                    holder.setVisible(R.id.waiting_topay_tv, true);
                    ImageView v1 = (ImageView) holder.getView(R.id.item_list_mine_dingdang_img2);
                    ObjectUtils.photo2(mContext, mineChoujiangdata.getThumb(), v1);
                    int c_time1 = Integer.parseInt(mineChoujiangdata.getC_time());
                    long msl1 = (long) c_time1 * 1000;
                    SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String text1 = format1.format(msl1);
                    ((TextView) holder.getView(R.id.turnover_time)).setText(text1);
                    ((TextView) holder.getView(R.id.marking_price2)).setText(mineChoujiangdata.getMarket_price());
                    ((TextView) holder.getView(R.id.turnover_price)).setText(mineChoujiangdata.getPrice());
                    ((TextView) holder.getView(R.id.bid_number2)).setText(mineChoujiangdata.getMid_count());
                    ((TextView) holder.getView(R.id.turnover_people)).setText(mineChoujiangdata.getUsername());
                    float percent1 = (Float.parseFloat(mineChoujiangdata.getPrice()) / Float.parseFloat(mineChoujiangdata.getMarket_price()))*100;
                    float savepercent1 = 100 - percent1;
                    DecimalFormat df1 = new DecimalFormat(".00");
                    String aishang_savepercent1 =df1.format(savepercent1);
                    holder.setText(R.id.save_percent, aishang_savepercent1+"%");
                    holder.setText(R.id.waiting_topay_tv, "去支付");
                    break;
                case 4:
                    //待收货
                    holder.setVisible(R.id.auctioning_ll, false);
                    holder.setVisible(R.id.promised_ll,false);
                    holder.setVisible(R.id.auction_ll, true);
                    holder.setVisible(R.id.waiting_topay_tv, true);
                    ImageView v4 = (ImageView) holder.getView(R.id.item_list_mine_dingdang_img2);
                    ObjectUtils.photo2(mContext, mineChoujiangdata.getThumb(), v4);
                    int c_time4 = Integer.parseInt(mineChoujiangdata.getC_time());
                    long msl4 = (long) c_time4 * 1000;
                    SimpleDateFormat format4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String text4 = format4.format(msl4);
                    ((TextView) holder.getView(R.id.turnover_time)).setText(text4);
                    ((TextView) holder.getView(R.id.marking_price2)).setText(mineChoujiangdata.getMarket_price());
                    ((TextView) holder.getView(R.id.turnover_price)).setText(mineChoujiangdata.getPrice());
                    ((TextView) holder.getView(R.id.bid_number2)).setText(mineChoujiangdata.getMid_count());
                    ((TextView) holder.getView(R.id.turnover_people)).setText(mineChoujiangdata.getUsername());
                    float percent4 = (Float.parseFloat(mineChoujiangdata.getPrice()) / Float.parseFloat(mineChoujiangdata.getMarket_price()))*100;
                    float savepercent4 = 100 - percent4;
                    DecimalFormat df4 = new DecimalFormat(".00");
                    String aishang_savepercent4 =df4.format(savepercent4);
                    holder.setText(R.id.save_percent, aishang_savepercent4+"%");
                    holder.setText(R.id.waiting_topay_tv, "确认收货");
                    break;
                case 5:
                    //待晒单
                    holder.setVisible(R.id.auctioning_ll, false);
                    holder.setVisible(R.id.promised_ll,false);
                    holder.setVisible(R.id.auction_ll, true);
                    holder.setVisible(R.id.waiting_topay_tv, true);
                    ImageView v5 = (ImageView) holder.getView(R.id.item_list_mine_dingdang_img2);
                    ObjectUtils.photo2(mContext, mineChoujiangdata.getThumb(), v5);
                    int c_time5 = Integer.parseInt(mineChoujiangdata.getC_time());
                    long msl5 = (long) c_time5 * 1000;
                    SimpleDateFormat format5 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String text5 = format5.format(msl5);
                    ((TextView) holder.getView(R.id.turnover_time)).setText(text5);
                    ((TextView) holder.getView(R.id.marking_price2)).setText(mineChoujiangdata.getMarket_price());
                    ((TextView) holder.getView(R.id.turnover_price)).setText(mineChoujiangdata.getPrice());
                    ((TextView) holder.getView(R.id.bid_number2)).setText(mineChoujiangdata.getMid_count());
                    ((TextView) holder.getView(R.id.turnover_people)).setText(mineChoujiangdata.getUsername());
                    float percent5 = (Float.parseFloat(mineChoujiangdata.getPrice()) / Float.parseFloat(mineChoujiangdata.getMarket_price()))*100;
                    float savepercent5 = 100 - percent5;
                    DecimalFormat df5 = new DecimalFormat(".00");
                    String aishang_savepercent5 =df5.format(savepercent5);
                    holder.setText(R.id.save_percent, aishang_savepercent5+"%");
                    holder.setText(R.id.waiting_topay_tv, "去晒单");
//                    holder.setVisible(R.id.back_score, true);
//                    holder.setText(R.id.back_score, "已返回" + mineChoujiangdata.getReturns_score() + "积分");
                    break;
                case 9:
                    //领取超时
                    holder.setVisible(R.id.auctioning_ll, false);
                    holder.setVisible(R.id.promised_ll,false);
                    holder.setVisible(R.id.auction_ll,true);
                    ImageView v9 = (ImageView) holder.getView(R.id.item_list_mine_dingdang_img2);
                    ObjectUtils.photo2(mContext, mineChoujiangdata.getThumb(), v9);
                    int c_time9 = Integer.parseInt(mineChoujiangdata.getC_time());
                    long msl9 = (long) c_time9 * 1000;
                    SimpleDateFormat format9 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String text9 = format9.format(msl9);
                    ((TextView) holder.getView(R.id.turnover_time)).setText(text9);
                    ((TextView) holder.getView(R.id.marking_price2)).setText(mineChoujiangdata.getMarket_price());
                    ((TextView) holder.getView(R.id.turnover_price)).setText(mineChoujiangdata.getPrice());
                    holder.setVisible(R.id.bid_number2_ll, false);
                    ((TextView) holder.getView(R.id.turnover_people)).setText(mineChoujiangdata.getUsername());
                    String aishang_savepercent9 = "0%";
                    holder.setText(R.id.save_percent, aishang_savepercent9);
                    holder.setVisible(R.id.waiting_topay_tv, false);
//                    holder.setVisible(R.id.back_score, true);
//                    holder.setText(R.id.back_score, "已返回" + mineChoujiangdata.getReturns_score() + "积分");
                    break;

                case 10:
                    holder.setVisible(R.id.auctioning_ll, false);
                    holder.setVisible(R.id.promised_ll,true);
                    holder.setVisible(R.id.auction_ll,false);
                    ImageView v10 = (ImageView) holder.getView(R.id.item_list_mine_dingdang_img3);
                    ObjectUtils.photo2(mContext, mineChoujiangdata.getThumb(), v10);
                    int c_time10 = Integer.parseInt(mineChoujiangdata.getC_time());
                    long msl10 = (long) c_time10 * 1000;
                    SimpleDateFormat format10 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String text10 = format10.format(msl10);
                    ((TextView) holder.getView(R.id.turnover_time1)).setText(text10);
                    break;
                default:
                    holder.setVisible(R.id.auctioning_ll, false);
                    holder.setVisible(R.id.promised_ll,false);
                    holder.setVisible(R.id.auction_ll, true);
                    ImageView v11 = (ImageView) holder.getView(R.id.item_list_mine_dingdang_img2);
                    ObjectUtils.photo2(mContext, mineChoujiangdata.getThumb(), v11);
                    int c_time11 = Integer.parseInt(mineChoujiangdata.getC_time());
                    long msl11 = (long) c_time11 * 1000;
                    SimpleDateFormat format11 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String text11 = format11.format(msl11);
                    ((TextView) holder.getView(R.id.turnover_time)).setText(text11);
                    ((TextView) holder.getView(R.id.marking_price2)).setText(mineChoujiangdata.getMarket_price());
                    ((TextView) holder.getView(R.id.turnover_price)).setText(mineChoujiangdata.getPrice());
                    ((TextView) holder.getView(R.id.bid_number2)).setText(mineChoujiangdata.getMid_count());
                    ((TextView) holder.getView(R.id.turnover_people)).setText(mineChoujiangdata.getUsername());
                    float percent11 = (Float.parseFloat(mineChoujiangdata.getPrice()) / Float.parseFloat(mineChoujiangdata.getMarket_price()))*100;
                    float savepercent11 = 100 - percent11;
                    DecimalFormat df11 = new DecimalFormat(".00");
                    String aishang_savepercent11 =df11.format(savepercent11);
                    holder.setText(R.id.save_percent, aishang_savepercent11+"%");
                    break;
            }
            if(!Mid.equals(mineChoujiangdata.getMid())){
                holder.setVisible(R.id.waiting_topay_tv, false);
                holder.setVisible(R.id.item_list_mine_dingdang_winning_bg, false);
            }else {
                holder.setVisible(R.id.item_list_mine_dingdang_winning_bg, true);
            }
        }
//
//
        holder.addOnClickListener(R.id.waiting_topay_tv);
        holder.addOnClickListener(R.id.go_on_auctioning_ll);
//        holder.addOnClickListener(R.id.daipinjia_wuliu);
//        holder.addOnClickListener(R.id.daishouhuo_daifahuo_detail);
//        holder.addOnClickListener(R.id.daishouhuo_daifahuo_lianximaijia);
//        holder.addOnClickListener(R.id.daishouhuo_wuliu);
//
//        holder.addOnClickListener(R.id.daishouhuo_queren);
//        holder.addOnClickListener(R.id.daifukuang_pay);
//        holder.addOnClickListener(R.id.daifukuang_canceldingdang);
//        holder.addOnClickListener(R.id.item_list_mine_dingdang_lottery_result);
//        holder.addOnClickListener(R.id.daipinjia_detele);


    }


}
